<?php

namespace App\Http\Controllers\Kms\App\Task;

use App\Enums\OpenShop\InvestmentPromotion\SiteLocationEnum;
use App\Http\Controllers\BaseController;
use App\Http\Validate\Kms\Task\TaskValidate;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationModel;
use App\Remote\Rms\RmsShopRemote;
use App\Service\Kms\Task\TaskService;
use App\Service\Kms\Task\TaskTotalService;
use App\Service\Kms\Task\UserRoleService;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class TaskController extends BaseController
{

    /**
     * @return JsonResponse
     * @throws Exception
     */
    public function preShopList(): JsonResponse
    {
        return $this->success(TaskService::preShopList());
    }


    /**
     * 日常任务门店列表
     *
     * @return JsonResponse
     * @throws GuzzleException
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function shopList(): JsonResponse
    {
        return $this->success(TaskService::shopListV2(TaskValidate::shopListValidate()));
    }


    /**
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function supervisorList(): JsonResponse
    {
        return $this->success(TaskService::supervisorList(TaskValidate::supervisorListValidate()));
    }

    /**
     * 日常任务创建
     *
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     * @throws Exception
     */
    public function add(): JsonResponse
    {
        TaskService::add(TaskValidate::addValidate(), auth()->user()->rmsUserId);
        return $this->success();
    }

    /**
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws GuzzleException
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function detail(): JsonResponse
    {
        return $this->success(TaskService::detail(TaskValidate::detailValidate()));
    }

    /**
     * 任务表单提交
     *
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function submit(): JsonResponse
    {
        TaskService::submit(TaskValidate::submitValidate());
        return $this->success();
    }

    /**
     * 作废任务
     *
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function invalid(): JsonResponse
    {
        TaskService::invalid(TaskValidate::invalidValidate());
        return $this->success();
    }

    /**
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function approval(): JsonResponse
    {
        TaskService::approval(TaskValidate::approvalValidate());
        return $this->success();
    }


    /**
     * 任务总览
     * @param Request $request
     * @return JsonResponse
     */
    public function total(Request $request): JsonResponse
    {
        $rmsUserId     = request()->user()->rmsUserId;
        $userIds       = (string)$request->get("userId", '');
        $shopName      = (string)$request->get("shopName", '');// 门店id/编号/商家名称
        $handlerName   = (string)$request->get("handlerName", '');// 处理人
        $fyName        = (string)$request->get("fyName", '');// 房源编号/名称，地址
        $grade         = (string)$request->get('grade', '');        //网规等级 多个逗号隔开
        $sort          = (string)$request->get('sort', '');         //排序 grade/updatedAt
        $provinceCodes = (string)$request->get("provinceCodes", '');//省code 多个逗号隔开
        $cityCodes     = (string)$request->get("cityCodes", '');    //市code 多个逗号隔开
        $areaCodes     = (string)$request->get("areaCodes", '');    //区code 多个逗号隔开

        $userIds       = $userIds ? explode(',', $userIds) : [];
        $grade         = $grade ? explode(',', $grade) : [];
        $provinceCodes = $provinceCodes ? explode(',', $provinceCodes) : [];
        $cityCodes     = $cityCodes ? explode(',', $cityCodes) : [];
        $areaCodes     = $areaCodes ? explode(',', $areaCodes) : [];

        $search = [
            'shopName'      => $shopName,
            'handlerName'   => $handlerName,
            'fyName'        => $fyName,
            'grade'         => $grade,
            'sort'          => $sort,
            'provinceCodes' => $provinceCodes,
            'cityCodes'     => $cityCodes,
            'areaCodes'     => $areaCodes,
        ];

        $count = TaskTotalService::countTotal($rmsUserId, $userIds, $search);
        return $this->success($count);
    }


    /**
     * 任务总列表
     * @param Request $request
     * @return JsonResponse
     * @throws GuzzleException
     */
    public function list(Request $request): JsonResponse
    {
        $isOperate     = (int)$request->get('isOperate', 0);//是否待处理 默认0-全部 1-需要我处理
        $type          = (string)$request->get('type', '');
        $userIds       = (string)$request->get("userId", '');
        $shopName      = (string)$request->get("shopName", '');// 门店id/编号/商家名称
        $handlerName   = (string)$request->get("handlerName", '');// 处理人
        $fyName        = (string)$request->get("fyName", '');// 房源编号/名称，地址
        $pageNum       = (int)$request->get('pageNum', 1);
        $pageSize      = (int)$request->get('pageSize', 10);
        $grade         = (string)$request->get('grade', '');        //网规等级 多个逗号隔开
        $sort          = (string)$request->get('sort', '');         //排序 grade/updatedAt
        $provinceCodes = (string)$request->get("provinceCodes", '');//省code 多个逗号隔开
        $cityCodes     = (string)$request->get("cityCodes", '');    //市code 多个逗号隔开
        $areaCodes     = (string)$request->get("areaCodes", '');    //区code 多个逗号隔开
        $collect       = (int)$request->get('collect', 0);          //是否收藏
        $orderNo       = (string)$request->get('orderNo', '');      // 搜索订单号

        $userIds       = $userIds ? explode(',', $userIds) : [];
        $types         = $type ? explode(',', $type) : [];
        $grade         = $grade ? explode(',', $grade) : [];
        $provinceCodes = $provinceCodes ? explode(',', $provinceCodes) : [];
        $cityCodes     = $cityCodes ? explode(',', $cityCodes) : [];
        $areaCodes     = $areaCodes ? explode(',', $areaCodes) : [];

        if ($collect) {//收藏任务 目前只有勘址有
            $types = [
                TaskTotalService::TYPE_29,
                TaskTotalService::TYPE_30,
                TaskTotalService::TYPE_31,
                TaskTotalService::TYPE_32,
                TaskTotalService::TYPE_33,
                TaskTotalService::TYPE_34,
            ];
        }

        $search    = [
            'shopName'      => $shopName,
            'handlerName'   => $handlerName,
            'fyName'        => $fyName,
            'grade'         => $grade,
            'sort'          => $sort,
            'provinceCodes' => $provinceCodes,
            'cityCodes'     => $cityCodes,
            'areaCodes'     => $areaCodes,
            'collect'       => $collect,
            'orderNo'       => $orderNo,
        ];
        $rmsUserId = request()->user()->rmsUserId;
        $list      = TaskTotalService::getList($rmsUserId, $isOperate, $types, $userIds, $pageNum, $pageSize, $search);
        return $this->success($list);
    }


    /**
     * 员工列表
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function staffList(Request $request): JsonResponse
    {
        $type     = (int)$request->get('type', 0);        //默认 0-督导 1-选址
        $branchId = (int)$request->get('branchId', 0);    //按分公司筛选
        $month    = (string)$request->get('month', '');   //月份 2023-08

        $rmsUserId = request()->user()->rmsUserId;
        $list      = TaskTotalService::staffList($rmsUserId, $type, $branchId, $month);
        return $this->success($list);
    }


    /**
     * 根据身份获取分公司列表
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function branchList(Request $request): JsonResponse
    {
        $rmsUserId = request()->user()->rmsUserId;
        $list      = TaskTotalService::branchList($rmsUserId);
        return $this->success($list);
    }


    /**
     * 保存员工任务目标
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function setStaffTarget(Request $request): JsonResponse
    {
        $this->validate(
            $request, [
                'data'  => 'required|array',
                'month' => 'required|string', // 月份 2023-08
            ]
        );

        $rmsUserId = request()->user()->rmsUserId;
        return $this->success(TaskTotalService::setStaffTarget($request, $rmsUserId));
    }


    /**
     * 用户列表
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function staffUserList(Request $request): JsonResponse
    {
        $rmsUserId = request()->user()->rmsUserId;
        $list      = TaskTotalService::staffUserList($rmsUserId);
        return $this->success($list);
    }



    /**
     * 门店筛选枚举-运营app-门店tab
     * @return JsonResponse
     */
    public function shopSift(): JsonResponse
    {
        $rmsUserId   = request()->user()->rmsUserId;
        $getUserRole = UserRoleService::getUserRole($rmsUserId);
        $role        = $getUserRole['role'] ?? UserRoleService::ROLE_SPECIAL_NO_ACCESS;
        return $this->success(
            [
                'area'      => in_array($role, [UserRoleService::ROLE_BASE_SUPERVISOR, UserRoleService::ROLE_BASE_PREPARE]) ? false : true,
                'shopType'  => collect(TaskTotalService::STORE_TAG_TEXT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'shopGrade' => collect(TaskTotalService::SHOP_GRADE_TEXT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'tag'       => collect(TaskTotalService::SHOP_TAG_TEXT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
            ]
        );
    }

    /**
     * 门店tab总览
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function shopTotal(Request $request): JsonResponse
    {
        $search = self::baseSearchShopTotal($request);
        $count  = TaskTotalService::shopTotal($search['rmsUserId'], $search);
        return $this->success($count);
    }

    /**
     * 门店tab-baseSearch
     * @param Request $request
     * @return array
     */
    public function baseSearchShopTotal(Request $request): array
    {
        $rmsUserId              = request()->user()->rmsUserId;
        $shopGrade              = (string)$request->get('shopGrade', '');         //门店最近营业额评级 明星,金牛
        $shopType               = (string)$request->get('shopType', '');          //门店类型 商场,街边,景区,高校
        $tags                   = (string)$request->get('tag', '');               //状态标签 选址活跃,选址沉默,筹备正常,筹备异常,开业报告未完成
        $contractStartTime      = (string)$request->get('contractStartTime', ''); //签约时间
        $contractEndTime        = (string)$request->get('contractEndTime', '');
        $siteStartTime          = (string)$request->get('siteStartTime', '');//落址时间
        $siteEndTime            = (string)$request->get('siteEndTime', '');
        $startBusinessStartTime = (string)$request->get('startBusinessStartTime', '');//开业时间选择
        $startBusinessEndTime   = (string)$request->get('startBusinessEndTime', '');
        $shopName               = (string)$request->get("shopName", '');     // 门店id/编号/商家名称
        $type                   = (string)$request->get('type', '');
        $branch                 = (string)$request->get('branch', '');  //分公司
        $branchId               = (string)$request->get('branchId', '');  //分公司Id
        $province               = (string)$request->get('province', '');//省
        $city                   = (string)$request->get('city', '');    //市
        $district               = (string)$request->get('district', '');//区
        $warZoneId              = (string)$request->get('warZoneId', '');  //战区Id
        $orderNo                = (string)$request->get('orderNo', '');  // 搜索单号


        $shopGrade    = $shopGrade ? explode(',', $shopGrade) : [];
        $shopType     = $shopType ? explode(',', $shopType) : [];
        $tags         = $tags ? explode(',', $tags) : [];
        $types        = $type ? explode(',', $type) : [];

        $tagIds = $cruiseOrderStatus = $shopTypes = $shopGrades = [];
        if ($shopGrade) {
            foreach ($shopGrade as $v) {
                $temp = TaskTotalService::SHOP_GRADE_TEXT_MAPPING[$v] ?? [];
                if (!$temp) {
                    continue;
                }
                $shopGrades[] = $temp;
            }
        }
        if ($tags) {
            foreach ($tags as $v) {
                $temp = TaskTotalService::SHOP_TAG_VALUE_MAPPING[$v] ?? [];
                if (!$temp) {
                    continue;
                }
                if ($v == TaskTotalService::SHOP_TAG_5) {
                    $cruiseOrderStatus = $temp;//开业报告未完成 包括了未提交，审批中和修改中
                } else {
                    $tagIds = array_merge($tagIds, $temp);
                }
            }
        }
        if ($shopType) {
            foreach ($shopType as $v) {
                $temp = TaskTotalService::STORE_TAG_VALUE_MAPPING[$v] ?? [];
                if (!$temp) {
                    continue;
                }
                $shopTypes[] = $temp;
            }
        }
        if ($types == [TaskTotalService::TYPE_8, TaskTotalService::TYPE_9, TaskTotalService::TYPE_10, TaskTotalService::TYPE_11]) {
            $types = [TaskTotalService::TYPE_8, TaskTotalService::TYPE_9];// 已开业 查询正常营业&暂停营业
        }
        return [
            'shopName'               => $shopName,
            'shopGrade'              => $shopGrades,
            'shopType'               => $shopTypes,
            'tagIds'                 => $tagIds,           // 筹备标签
            'cruiseOrderStatus'      => $cruiseOrderStatus,//开业报告未完成 包括了未提交，审批中和修改中
            'contractStartTime'      => $contractStartTime,
            'contractEndTime'        => $contractEndTime,
            'siteStartTime'          => $siteStartTime,
            'siteEndTime'            => $siteEndTime,
            'startBusinessStartTime' => $startBusinessStartTime,
            'startBusinessEndTime'   => $startBusinessEndTime,
            'types'                  => $types,
            'branch'                 => $branch,
            'branchId'               => $branchId,
            'province'               => $province,
            'city'                   => $city,
            'district'               => $district,
            'rmsUserId'              => $rmsUserId,
            'warZoneId'              => $warZoneId,
            'orderNo'                => $orderNo,
        ];
    }

    /**
     * 门店tab-列表
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function shopTabList(Request $request): JsonResponse
    {
        $search   = self::baseSearchShopTotal($request);
        $pageSize = (int)$request->get('pageSize', 20);
        $pageNum  = (int)$request->get('pageNum', 1);
        return $this->success(TaskTotalService::shopTabList($search['rmsUserId'], $search, $pageSize, $pageNum));
    }

    /**
     * 分公司列表
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function clueClassify(Request $request): JsonResponse
    {
        $lng  = $request->get('lng', 0);
        $lat  = $request->get('lat', 0);
        $type = $request->get('type', '');

        $rmsUserId = request()->user()->rmsUserId;
        return $this->success(TaskTotalService::clueClassify($lng, $lat, $rmsUserId, $type));
    }



    /**
     * 房源筛选枚举-运营app-选址tab-房源
     * @return JsonResponse
     */
    public function houseSearchSiftNew(): JsonResponse
    {
        return $this->success(
            [
                'status'  => collect(OpenShopSiteLocationModel::CLUE_SEARCH_STATUS_MAP)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'grade'   => collect(OpenShopSiteLocationModel::HOUSE_SHOP_GRADE_SIFT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'type'    => collect(SiteLocationEnum::SHOP_SEARCH_MODEL_TYPE_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'area'    => collect(OpenShopSiteLocationModel::HOUSE_SEARCH_AREA_SIFT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'rent'    => collect(OpenShopSiteLocationModel::HOUSE_SEARCH_RENT_SIFT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'groupBy' => collect(OpenShopSiteLocationModel::HOUSE_SEARCH_GROUP_BY_SIFT_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
            ]
        );
    }

    /**
     * 房源列表
     * @param Request $request
     * @return JsonResponse
     */
    public function houseResourcesList(Request $request): JsonResponse
    {
        $type         = (string)$request->get('type', '');
        $status       = (string)$request->get('status', '');
        $branchId     = (int)$request->get('branchId', 0);
        $provinceCode = (string)$request->get('provinceCode', '');
        $cityCode     = (string)$request->get('cityCode', '');
        $areaCode     = (string)$request->get('districtCode', '');
        $pageNum      = (int)$request->get('pageNum', 1);
        $pageSize     = (int)$request->get('pageSize', 10);
        $groupBy      = (int)$request->get('groupBy', 0);
        $grade        = (string)$request->get('grade', '');
        $rent         = (string)$request->get('rent', '');
        $area         = (string)$request->get('area', '');
        $name         = (string)$request->get('name', '');
        $isOwn        = (bool)$request->get('isOwn', false);//true 只看自己的
        $orderNo      = (string)$request->get('orderNo', '');// 列表查询单个数据

        $rmsUserId    = request()->user()->rmsUserId;
        $type         = $type ? explode(',', $type) : [];
        $status       = $status ? explode(',', $status) : [];
        $provinceCode = $provinceCode ? explode(',', $provinceCode) : [];
        $cityCode     = $cityCode ? explode(',', $cityCode) : [];
        $areaCode     = $areaCode ? explode(',', $areaCode) : [];
        $grade        = $grade ? explode(',', $grade) : [];
        $rent         = $rent ? explode(',', $rent) : [];
        $area         = $area ? explode(',', $area) : [];

        $shopModelType = $clueStatus = [];
        foreach ($type as $v) {
            $shopModelType = array_merge($shopModelType, SiteLocationEnum::SHOP_SEARCH_MODEL_VALUE_MAPPING[$v] ?? []);
        }
        foreach ($status as $v) {
            $clueStatus = array_merge($clueStatus, OpenShopSiteLocationModel::CLUE_SEARCH_STATUS_VALUE_MAP[$v] ?? []);
        }
        if ($provinceCode) {
            $branchId = 0;
        }
        $search = [
            'shopModelType' => $shopModelType,
            'clueStatus'    => $clueStatus,
            'branchId'      => $branchId,
            'provinceCode'  => $provinceCode,
            'cityCode'      => $cityCode,
            'areaCode'      => $areaCode,
            'pageNum'       => $pageNum,
            'pageSize'      => $pageSize,
            'groupBy'       => $groupBy,
            'grade'         => $grade,
            'rent'          => $rent,
            'area'          => $area,
            'name'          => $name,
            'isOwn'         => $isOwn,
            'orderNo'       => $orderNo,
        ];
        return $this->success(TaskTotalService::houseResourcesList($rmsUserId, $search));
    }


    /**
     * 落址筛选枚举-运营app-选址tab-落址
     * @return JsonResponse
     */
    public function siteLocationsSearchSift(): JsonResponse
    {
        $rmsUserId   = request()->user()->rmsUserId;
        $getUserRole = UserRoleService::getUserRole($rmsUserId);
        $role        = $getUserRole['role'] ?? UserRoleService::ROLE_SPECIAL_NO_ACCESS;
        $statusArr   = TaskTotalService::SITE_LOCATION_SEARCH_MAPPING;
        if (in_array($role, [UserRoleService::ROLE_BASE_SITE_SELECTION_DEVELOPMENT, UserRoleService::ROLE_BASE_KAM])) {
             unset($statusArr[TaskTotalService::TYPE_6]);// 开发人员不看开发待指派
        }
        return $this->success(
            [
                'type'  => collect($statusArr)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
                'tag'   => collect(TaskTotalService::SITE_LOCATION_SEARCH_TAG_MAPPING)->map(
                    function ($text, $value) {
                        return compact('text', 'value');
                    }
                )->values()->toArray(),
            ]
        );
    }

    /**
     * 落址
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function siteLocationsTotal(Request $request): JsonResponse
    {
        $search = self::siteLocationsBaseSearch($request);

        $count = TaskTotalService::siteLocationsTotal($search['rmsUserId'], $search['userIds'], $search);
        return $this->success($count);
    }

    /**
     * 落址Search
     * @param Request $request
     * @return array
     */
    public function siteLocationsBaseSearch(Request $request): array
    {
        $rmsUserId     = request()->user()->rmsUserId;
        $userIds       = (string)$request->get("userId", '');
        $type          = (string)$request->get('type', '');
        $isOperate     = (int)$request->get('isOwn', 0);//是否待处理 默认0-全部 1-需要我处理
        $userIds       = (string)$request->get("userId", '');
        $name          = (string)$request->get("name", '');           // 商家名称
        $dealName      = (string)$request->get("dealName", '');       // 处理人名称
        $branchId      = (int)$request->get('branchId', 0);
        $provinceCodes = (string)$request->get("provinceCode", '');//省code 多个逗号隔开
        $cityCodes     = (string)$request->get("cityCode", '');    //市code 多个逗号隔开
        $areaCodes     = (string)$request->get("districtCode", '');    //区code 多个逗号隔开
        $tags          = (string)$request->get("tag", '');
        $orderNo       = (string)$request->get('orderNo', '');// 列表查询单个数据

        $tagIds        = [];
        $userIds       = $userIds ? explode(',', $userIds) : [];
        $types         = $type ? explode(',', $type) : [];
        $tags          = $tags ? explode(',', $tags) : [];
        $provinceCodes = $provinceCodes ? explode(',', $provinceCodes) : [];
        $cityCodes     = $cityCodes ? explode(',', $cityCodes) : [];
        $areaCodes     = $areaCodes ? explode(',', $areaCodes) : [];
        if ($areaCodes) {
            $cityCodes = $provinceCodes = [];
            $branchId  = 0;
        }
        if ($cityCodes) {
            $areaCodes = $provinceCodes = [];
            $branchId  = 0;
        }
        if ($provinceCodes) {
            $cityCodes = $areaCodes = [];
            $branchId  = 0;
        }
        if ($branchId) {
            $provinceCodes = $cityCodes = $areaCodes = [];
        }
        if ($tags) {
            foreach ($tags as $v) {
                $temp = TaskTotalService::SITE_LOCATION_SEARCH_TAG_ID_MAPPING[$v] ?? [];
                if (!$temp) {
                    continue;
                }
                $tagIds = array_merge($tagIds, $temp);
            }
        }
        return [
            'name'          => $name,
            'dealName'      => $dealName,
            'branchId'      => $branchId,
            'provinceCodes' => $provinceCodes,
            'cityCodes'     => $cityCodes,
            'areaCodes'     => $areaCodes,
            'isOperate'     => $isOperate,
            'tagIds'        => $tagIds,
            'types'         => $types,
            'userIds'       => $userIds,
            'rmsUserId'     => $rmsUserId,
            'orderNo'       => $orderNo,
        ];
    }

    /**
     * 落址列表
     * @param Request $request
     * @return JsonResponse
     */
    public function siteLocationsList(Request $request): JsonResponse
    {
        $search   = self::siteLocationsBaseSearch($request);
        $pageNum  = (int)$request->get('pageNum', 1);
        $pageSize = (int)$request->get('pageSize', 10);

        $list = TaskTotalService::siteLocationsList($search['rmsUserId'], $search['userIds'], $search['isOperate'], $pageNum, $pageSize, $search);
        return $this->success($list);
    }

    /**
     * 任务记录
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function processList(Request $request): JsonResponse
    {
        $this->validate(
            $request, [
                'orderNo' => 'required|string',
            ]
        );
        $orderNo = (string)$request->get('orderNo', '');
        $list    = TaskTotalService::processList($orderNo);
        return $this->success($list);
    }

    /**
     * 照片素材
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function photoList(Request $request): JsonResponse
    {
        $this->validate(
            $request, [
                'orderNo' => 'required|string',
            ]
        );
        $orderNo  = (string)$request->get('orderNo', '');
        $pageNum  = (int)$request->get('pageNum', 1);
        $pageSize = (int)$request->get('pageSize', 10);
        $list     = TaskTotalService::photoList($orderNo, $pageNum, $pageSize);
        return $this->success($list);
    }

    /**
     * 年费订单+续签订单列表
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function shopOrderList(Request $request): JsonResponse
    {
        $this->validate(
            $request, [
                'orderNo' => 'required|string',
            ]
        );
        $orderNo = (string)$request->get('orderNo', '');
        $list = TaskTotalService::shopOrderList($orderNo);
        return $this->success($list);
    }


    /**
     * 门店风云榜
     * @param Request $request
     * @return JsonResponse
     */
    public function getWindCloudRank(Request $request): JsonResponse
    {
        $searchData = $request->all();
        $rmsUserId  = request()->user()->rmsUserId;
        return $this->success(TaskTotalService::getWindCloudRank($searchData, $rmsUserId));
    }


    /**
     * 营业指标数据
     * @param Request $request
     * @return JsonResponse
     * @throws GuzzleException
     */
    public function getDashboardCruise(Request $request): JsonResponse
    {
        $shopId = (int)$request->get('shopId', 0);
        $res    = RmsShopRemote::getDashboardCruise(array_merge($request->all(), ["kmsShopId" => $shopId]));
        return $this->success($res);
    }
}
